import sqlite3

DB_URL = 'apps.db'

def where_am_i(self, macs):
    locations = []
    for mac in macs:
        c = sqlite3.connect(DB_URL).cursor()
        c.execute(''' select room from aps where mac=? ''', (mac,))
        location = None
        for row in c:
            if location:
                raise
            location = row[0]
        if location:
            locations.append(location)
    return locations
    
if __name__ == '__main__':
    # Some test code
    a = APLookup()
    locations = a.where_am_i(['00-30-F1-79-2C-57'])
    # Should be 023
    assert len(locations) == 1
    assert locations[0] == 23
    
    def are_comprable(list1, list2):
        if len(list1) != len(list2):
            return False
        for item in list1:
            if item not in list2:
                return False
        for item in list2:
            if item not in list1:
                return False
        return True
    
    locations = a.where_am_i(['00-02-2D-2E-57-10', '00-20-A6-4F-2A-F6'])
    assert are_comprable([441, 3], locations)
    print 'yes!'
